<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><link rel="stylesheet" type="text/css" href="style.css" /><script type="text/javascript" src="highlight.js"></script></head><body><pre><span class="hs-comment">{-
(c) The University of Glasgow 2006
(c) The AQUA Project, Glasgow University, 1993-1998

-}</span><span>
</span><span id="line-6"></span><span>
</span><span id="line-7"></span><span class="hs-pragma">{-# LANGUAGE ViewPatterns #-}</span><span>
</span><span id="line-8"></span><span class="hs-pragma">{-# LANGUAGE TypeFamilies #-}</span><span>
</span><span id="line-9"></span><span>
</span><span id="line-10"></span><span class="hs-comment">-- | Typechecking rewrite rules</span><span>
</span><span id="line-11"></span><span class="hs-keyword">module</span><span> </span><span class="hs-identifier">GHC.Tc.Gen.Rule</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRules"><span class="hs-identifier">tcRules</span></a></span><span> </span><span class="hs-special">)</span><span> </span><span class="hs-keyword">where</span><span>
</span><span id="line-12"></span><span>
</span><span id="line-13"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Prelude.html"><span class="hs-identifier">GHC.Prelude</span></a></span><span>
</span><span id="line-14"></span><span>
</span><span id="line-15"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Hs.html"><span class="hs-identifier">GHC.Hs</span></a></span><span>
</span><span id="line-16"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html"><span class="hs-identifier">GHC.Tc.Types</span></a></span><span>
</span><span id="line-17"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Monad.html"><span class="hs-identifier">GHC.Tc.Utils.Monad</span></a></span><span>
</span><span id="line-18"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Solver.html"><span class="hs-identifier">GHC.Tc.Solver</span></a></span><span>
</span><span id="line-19"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html"><span class="hs-identifier">GHC.Tc.Types.Constraint</span></a></span><span>
</span><span id="line-20"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html"><span class="hs-identifier">GHC.Core.Predicate</span></a></span><span>
</span><span id="line-21"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Origin.html"><span class="hs-identifier">GHC.Tc.Types.Origin</span></a></span><span>
</span><span id="line-22"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcMType.html"><span class="hs-identifier">GHC.Tc.Utils.TcMType</span></a></span><span>
</span><span id="line-23"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html"><span class="hs-identifier">GHC.Tc.Utils.TcType</span></a></span><span>
</span><span id="line-24"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Gen.HsType.html"><span class="hs-identifier">GHC.Tc.Gen.HsType</span></a></span><span>
</span><span id="line-25"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Gen.Expr.html"><span class="hs-identifier">GHC.Tc.Gen.Expr</span></a></span><span>
</span><span id="line-26"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Env.html"><span class="hs-identifier">GHC.Tc.Utils.Env</span></a></span><span>
</span><span id="line-27"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Unify.html"><span class="hs-identifier">GHC.Tc.Utils.Unify</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.Unify.html#buildImplicationFor"><span class="hs-identifier">buildImplicationFor</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-28"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html"><span class="hs-identifier">GHC.Tc.Types.Evidence</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Evidence.html#mkTcCoVarCo"><span class="hs-identifier">mkTcCoVarCo</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-29"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.Type.html"><span class="hs-identifier">GHC.Core.Type</span></a></span><span>
</span><span id="line-30"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html"><span class="hs-identifier">GHC.Core.TyCon</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier">isTypeFamilyTyCon</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-31"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Id.html"><span class="hs-identifier">GHC.Types.Id</span></a></span><span>
</span><span id="line-32"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.html"><span class="hs-identifier">GHC.Types.Var</span></a></span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Var.html#EvVar"><span class="hs-identifier">EvVar</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-33"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Var.Set.html"><span class="hs-identifier">GHC.Types.Var.Set</span></a></span><span>
</span><span id="line-34"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html"><span class="hs-identifier">GHC.Types.Basic</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RuleName"><span class="hs-identifier">RuleName</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-35"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Types.SrcLoc.html"><span class="hs-identifier">GHC.Types.SrcLoc</span></a></span><span>
</span><span id="line-36"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html"><span class="hs-identifier">GHC.Utils.Outputable</span></a></span><span>
</span><span id="line-37"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html"><span class="hs-identifier">GHC.Data.FastString</span></a></span><span>
</span><span id="line-38"></span><span class="hs-keyword">import</span><span> </span><span class="annot"><a href="GHC.Data.Bag.html"><span class="hs-identifier">GHC.Data.Bag</span></a></span><span>
</span><span id="line-39"></span><span>
</span><span id="line-40"></span><span class="hs-comment">{-
Note [Typechecking rules]
~~~~~~~~~~~~~~~~~~~~~~~~~
We *infer* the typ of the LHS, and use that type to *check* the type of
the RHS.  That means that higher-rank rules work reasonably well. Here's
an example (test simplCore/should_compile/rule2.hs) produced by Roman:

   foo :: (forall m. m a -&gt; m b) -&gt; m a -&gt; m b
   foo f = ...

   bar :: (forall m. m a -&gt; m a) -&gt; m a -&gt; m a
   bar f = ...

   {-# RULES &quot;foo/bar&quot; foo = bar #-}

He wanted the rule to typecheck.

Note [TcLevel in type checking rules]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Bringing type variables into scope naturally bumps the TcLevel. Thus, we type
check the term-level binders in a bumped level, and we must accordingly bump
the level whenever these binders are in scope.

Note [Re-quantify type variables in rules]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Consider this example from #17710:

  foo :: forall k (a :: k) (b :: k). Proxy a -&gt; Proxy b
  foo x = Proxy
  {-# RULES &quot;foo&quot; forall (x :: Proxy (a :: k)). foo x = Proxy #-}

Written out in more detail, the &quot;foo&quot; rewrite rule looks like this:

  forall k (a :: k). forall (x :: Proxy (a :: k)). foo @k @a @b0 x = Proxy @k @b0

Where b0 is a unification variable. Where should b0 be quantified? We have to
quantify it after k, since (b0 :: k). But generalization usually puts inferred
type variables (such as b0) at the /front/ of the telescope! This creates a
conflict.

One option is to simply throw an error, per the principles of
Note [Naughty quantification candidates] in GHC.Tc.Utils.TcMType. This is what would happen
if we were generalising over a normal type signature. On the other hand, the
types in a rewrite rule aren't quite &quot;normal&quot;, since the notions of specified
and inferred type variables aren't applicable.

A more permissive design (and the design that GHC uses) is to simply requantify
all of the type variables. That is, we would end up with this:

  forall k (a :: k) (b :: k). forall (x :: Proxy (a :: k)). foo @k @a @b x = Proxy @k @b

It's a bit strange putting the generalized variable `b` after the user-written
variables `k` and `a`. But again, the notion of specificity is not relevant to
rewrite rules, since one cannot &quot;visibly apply&quot; a rewrite rule. This design not
only makes &quot;foo&quot; typecheck, but it also makes the implementation simpler.

See also Note [Generalising in tcTyFamInstEqnGuts] in GHC.Tc.TyCl, which
explains a very similar design when generalising over a type family instance
equation.
-}</span><span>
</span><span id="line-100"></span><span>
</span><span id="line-101"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRules"><span class="hs-identifier hs-type">tcRules</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LRuleDecls"><span class="hs-identifier hs-type">LRuleDecls</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LRuleDecls"><span class="hs-identifier hs-type">LRuleDecls</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-102"></span><span id="tcRules"><span class="annot"><span class="annottext">tcRules :: [LRuleDecls GhcRn] -&gt; TcM [LRuleDecls GhcTc]
</span><a href="GHC.Tc.Gen.Rule.html#tcRules"><span class="hs-identifier hs-var hs-var">tcRules</span></a></span></span><span> </span><span id="local-6989586621681175032"><span class="annot"><span class="annottext">[LRuleDecls GhcRn]
</span><a href="#local-6989586621681175032"><span class="hs-identifier hs-var">decls</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(LRuleDecls GhcRn
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (LRuleDecls GhcTc))
-&gt; [LRuleDecls GhcRn] -&gt; TcM [LRuleDecls GhcTc]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(RuleDecls GhcRn -&gt; TcM (RuleDecls GhcTc))
-&gt; LRuleDecls GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (LRuleDecls GhcTc)
forall a b. (a -&gt; TcM b) -&gt; Located a -&gt; TcM (Located b)
</span><a href="GHC.Tc.Utils.Monad.html#wrapLocM"><span class="hs-identifier hs-var">wrapLocM</span></a></span><span> </span><span class="annot"><span class="annottext">RuleDecls GhcRn -&gt; TcM (RuleDecls GhcTc)
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleDecls"><span class="hs-identifier hs-var">tcRuleDecls</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[LRuleDecls GhcRn]
</span><a href="#local-6989586621681175032"><span class="hs-identifier hs-var">decls</span></a></span><span>
</span><span id="line-103"></span><span>
</span><span id="line-104"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleDecls"><span class="hs-identifier hs-type">tcRuleDecls</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Hs.Decls.html#RuleDecls"><span class="hs-identifier hs-type">RuleDecls</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#RuleDecls"><span class="hs-identifier hs-type">RuleDecls</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-105"></span><span id="tcRuleDecls"><span class="annot"><span class="annottext">tcRuleDecls :: RuleDecls GhcRn -&gt; TcM (RuleDecls GhcTc)
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleDecls"><span class="hs-identifier hs-var hs-var">tcRuleDecls</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#HsRules"><span class="hs-identifier hs-type">HsRules</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rds_src :: forall pass. RuleDecls pass -&gt; SourceText
</span><a href="GHC.Hs.Decls.html#rds_src"><span class="hs-identifier hs-var">rds_src</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175026"><span class="annot"><span class="annottext">SourceText
</span><a href="#local-6989586621681175026"><span class="hs-identifier hs-var">src</span></a></span></span><span>
</span><span id="line-106"></span><span>                     </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rds_rules :: forall pass. RuleDecls pass -&gt; [LRuleDecl pass]
</span><a href="GHC.Hs.Decls.html#rds_rules"><span class="hs-identifier hs-var">rds_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175024"><span class="annot"><span class="annottext">[LRuleDecl GhcRn]
</span><a href="#local-6989586621681175024"><span class="hs-identifier hs-var">decls</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-107"></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681175023"><span class="annot"><span class="annottext">[Located (RuleDecl GhcTc)]
</span><a href="#local-6989586621681175023"><span class="hs-identifier hs-var">tc_decls</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(LRuleDecl GhcRn
 -&gt; IOEnv (Env TcGblEnv TcLclEnv) (Located (RuleDecl GhcTc)))
-&gt; [LRuleDecl GhcRn]
-&gt; IOEnv (Env TcGblEnv TcLclEnv) [Located (RuleDecl GhcTc)]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">(RuleDecl GhcRn -&gt; TcM (RuleDecl GhcTc))
-&gt; LRuleDecl GhcRn
-&gt; IOEnv (Env TcGblEnv TcLclEnv) (Located (RuleDecl GhcTc))
forall a b. (a -&gt; TcM b) -&gt; Located a -&gt; TcM (Located b)
</span><a href="GHC.Tc.Utils.Monad.html#wrapLocM"><span class="hs-identifier hs-var">wrapLocM</span></a></span><span> </span><span class="annot"><span class="annottext">RuleDecl GhcRn -&gt; TcM (RuleDecl GhcTc)
</span><a href="GHC.Tc.Gen.Rule.html#tcRule"><span class="hs-identifier hs-var">tcRule</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">[LRuleDecl GhcRn]
</span><a href="#local-6989586621681175024"><span class="hs-identifier hs-var">decls</span></a></span><span>
</span><span id="line-108"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleDecls GhcTc -&gt; TcM (RuleDecls GhcTc)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(RuleDecls GhcTc -&gt; TcM (RuleDecls GhcTc))
-&gt; RuleDecls GhcTc -&gt; TcM (RuleDecls GhcTc)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">HsRules :: forall pass.
XCRuleDecls pass
-&gt; SourceText -&gt; [LRuleDecl pass] -&gt; RuleDecls pass
</span><a href="GHC.Hs.Decls.html#HsRules"><span class="hs-identifier hs-type">HsRules</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rds_ext :: XCRuleDecls GhcTc
</span><a href="GHC.Hs.Decls.html#rds_ext"><span class="hs-identifier hs-var">rds_ext</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">NoExtField
XCRuleDecls GhcTc
</span><a href="GHC.Hs.Extension.html#noExtField"><span class="hs-identifier hs-var">noExtField</span></a></span><span>
</span><span id="line-109"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rds_src :: SourceText
</span><a href="GHC.Hs.Decls.html#rds_src"><span class="hs-identifier hs-var">rds_src</span></a></span><span>   </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">SourceText
</span><a href="#local-6989586621681175026"><span class="hs-identifier hs-var">src</span></a></span><span>
</span><span id="line-110"></span><span>                           </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rds_rules :: [Located (RuleDecl GhcTc)]
</span><a href="GHC.Hs.Decls.html#rds_rules"><span class="hs-identifier hs-var">rds_rules</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[Located (RuleDecl GhcTc)]
</span><a href="#local-6989586621681175023"><span class="hs-identifier hs-var">tc_decls</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-111"></span><span>
</span><span id="line-112"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRule"><span class="hs-identifier hs-type">tcRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Hs.Decls.html#RuleDecl"><span class="hs-identifier hs-type">RuleDecl</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#RuleDecl"><span class="hs-identifier hs-type">RuleDecl</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-113"></span><span id="tcRule"><span class="annot"><span class="annottext">tcRule :: RuleDecl GhcRn -&gt; TcM (RuleDecl GhcTc)
</span><a href="GHC.Tc.Gen.Rule.html#tcRule"><span class="hs-identifier hs-var hs-var">tcRule</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#HsRule"><span class="hs-identifier hs-type">HsRule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rd_ext :: forall pass. RuleDecl pass -&gt; XHsRule pass
</span><a href="GHC.Hs.Decls.html#rd_ext"><span class="hs-identifier hs-var">rd_ext</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175017"><span class="annot"><span class="annottext">XHsRule GhcRn
</span><a href="#local-6989586621681175017"><span class="hs-identifier hs-var">ext</span></a></span></span><span>
</span><span id="line-114"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_name :: forall pass. RuleDecl pass -&gt; Located (SourceText, RuleName)
</span><a href="GHC.Hs.Decls.html#rd_name"><span class="hs-identifier hs-var">rd_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175015"><span class="annot"><span class="annottext">rname :: Located (SourceText, RuleName)
</span><a href="#local-6989586621681175015"><span class="hs-identifier hs-var">rname</span></a></span></span><span class="hs-glyph">@</span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">SourceText
</span><span class="hs-identifier">_</span></span><span class="hs-special">,</span><span id="local-6989586621681175013"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681175013"><span class="hs-identifier hs-var">name</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span>
</span><span id="line-115"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_act :: forall pass. RuleDecl pass -&gt; Activation
</span><a href="GHC.Hs.Decls.html#rd_act"><span class="hs-identifier hs-var">rd_act</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175011"><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621681175011"><span class="hs-identifier hs-var">act</span></a></span></span><span>
</span><span id="line-116"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_tyvs :: forall pass.
RuleDecl pass -&gt; Maybe [LHsTyVarBndr () (NoGhcTc pass)]
</span><a href="GHC.Hs.Decls.html#rd_tyvs"><span class="hs-identifier hs-var">rd_tyvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175009"><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () (NoGhcTc GhcRn)]
</span><a href="#local-6989586621681175009"><span class="hs-identifier hs-var">ty_bndrs</span></a></span></span><span>
</span><span id="line-117"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_tmvs :: forall pass. RuleDecl pass -&gt; [LRuleBndr pass]
</span><a href="GHC.Hs.Decls.html#rd_tmvs"><span class="hs-identifier hs-var">rd_tmvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175007"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681175007"><span class="hs-identifier hs-var">tm_bndrs</span></a></span></span><span>
</span><span id="line-118"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_lhs :: forall pass. RuleDecl pass -&gt; Located (HsExpr pass)
</span><a href="GHC.Hs.Decls.html#rd_lhs"><span class="hs-identifier hs-var">rd_lhs</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175005"><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681175005"><span class="hs-identifier hs-var">lhs</span></a></span></span><span>
</span><span id="line-119"></span><span>               </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_rhs :: forall pass. RuleDecl pass -&gt; Located (HsExpr pass)
</span><a href="GHC.Hs.Decls.html#rd_rhs"><span class="hs-identifier hs-var">rd_rhs</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681175003"><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681175003"><span class="hs-identifier hs-var">rhs</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-120"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; TcM (RuleDecl GhcTc) -&gt; TcM (RuleDecl GhcTc)
forall a. MsgDoc -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#addErrCtxt"><span class="hs-identifier hs-var">addErrCtxt</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; MsgDoc
</span><a href="GHC.Tc.Gen.Rule.html#ruleCtxt"><span class="hs-identifier hs-var">ruleCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681175013"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span>  </span><span class="annot"><span class="annottext">(TcM (RuleDecl GhcTc) -&gt; TcM (RuleDecl GhcTc))
-&gt; TcM (RuleDecl GhcTc) -&gt; TcM (RuleDecl GhcTc)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-121"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;---- Rule ------&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Located (SourceText, RuleName) -&gt; MsgDoc
</span><a href="GHC.Hs.Decls.html#pprFullRuleName"><span class="hs-identifier hs-var">pprFullRuleName</span></a></span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName)
</span><a href="#local-6989586621681175015"><span class="hs-identifier hs-var">rname</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-122"></span><span>
</span><span id="line-123"></span><span>        </span><span class="hs-comment">-- Note [Typechecking rules]</span><span>
</span><span id="line-124"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174998"><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174998"><span class="hs-identifier hs-var">tc_lvl</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174997"><span class="annot"><span class="annottext">([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
 WantedConstraints, TcType)
</span><a href="#local-6989586621681174997"><span class="hs-identifier hs-var">stuff</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM
  ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
   WantedConstraints, TcType)
-&gt; TcM
     (TcLevel,
      ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
       WantedConstraints, TcType))
forall a. TcM a -&gt; TcM (TcLevel, a)
</span><a href="GHC.Tc.Utils.Monad.html#pushTcLevelM"><span class="hs-identifier hs-var">pushTcLevelM</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM
   ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
    WantedConstraints, TcType)
 -&gt; TcM
      (TcLevel,
       ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
        WantedConstraints, TcType)))
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
-&gt; TcM
     (TcLevel,
      ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
       WantedConstraints, TcType))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-125"></span><span>                            </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
-&gt; [LRuleBndr GhcRn]
-&gt; Located (HsExpr GhcRn)
-&gt; Located (HsExpr GhcRn)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
</span><a href="GHC.Tc.Gen.Rule.html#generateRuleConstraints"><span class="hs-identifier hs-var">generateRuleConstraints</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
Maybe [LHsTyVarBndr () (NoGhcTc GhcRn)]
</span><a href="#local-6989586621681175009"><span class="hs-identifier hs-var">ty_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681175007"><span class="hs-identifier hs-var">tm_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681175005"><span class="hs-identifier hs-var">lhs</span></a></span><span> </span><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681175003"><span class="hs-identifier hs-var">rhs</span></a></span><span>
</span><span id="line-126"></span><span>
</span><span id="line-127"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174994"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174994"><span class="hs-identifier hs-var">id_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174993"><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174993"><span class="hs-identifier hs-var">lhs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174992"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174992"><span class="hs-identifier hs-var">lhs_wanted</span></a></span></span><span>
</span><span id="line-128"></span><span>                      </span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174991"><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174991"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174990"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174990"><span class="hs-identifier hs-var">rhs_wanted</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174989"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174989"><span class="hs-identifier hs-var">rule_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
 WantedConstraints, TcType)
</span><a href="#local-6989586621681174997"><span class="hs-identifier hs-var">stuff</span></a></span><span>
</span><span id="line-129"></span><span>
</span><span id="line-130"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tcRule 1&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[MsgDoc] -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName) -&gt; MsgDoc
</span><a href="GHC.Hs.Decls.html#pprFullRuleName"><span class="hs-identifier hs-var">pprFullRuleName</span></a></span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName)
</span><a href="#local-6989586621681175015"><span class="hs-identifier hs-var">rname</span></a></span><span>
</span><span id="line-131"></span><span>                                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174992"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-132"></span><span>                                  </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174990"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span> </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-133"></span><span>
</span><span id="line-134"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174986"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174986"><span class="hs-identifier hs-var">lhs_evs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174985"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174985"><span class="hs-identifier hs-var">residual_lhs_wanted</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-135"></span><span>            </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">RuleName
-&gt; TcLevel
-&gt; WantedConstraints
-&gt; WantedConstraints
-&gt; TcM ([TcTyVar], WantedConstraints)
</span><a href="GHC.Tc.Gen.Rule.html#simplifyRule"><span class="hs-identifier hs-var">simplifyRule</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681175013"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174998"><span class="hs-identifier hs-var">tc_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174992"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174990"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span>
</span><span id="line-136"></span><span>
</span><span id="line-137"></span><span>       </span><span class="hs-comment">-- SimplfyRule Plan, step 4</span><span>
</span><span id="line-138"></span><span>       </span><span class="hs-comment">-- Now figure out what to quantify over</span><span>
</span><span id="line-139"></span><span>       </span><span class="hs-comment">-- c.f. GHC.Tc.Solver.simplifyInfer</span><span>
</span><span id="line-140"></span><span>       </span><span class="hs-comment">-- We quantify over any tyvars free in *either* the rule</span><span>
</span><span id="line-141"></span><span>       </span><span class="hs-comment">--  *or* the bound variables.  The latter is important.  Consider</span><span>
</span><span id="line-142"></span><span>       </span><span class="hs-comment">--      ss (x,(y,z)) = (x,z)</span><span>
</span><span id="line-143"></span><span>       </span><span class="hs-comment">--      RULE:  forall v. fst (ss v) = fst v</span><span>
</span><span id="line-144"></span><span>       </span><span class="hs-comment">-- The type of the rhs of the rule is just a, but v::(a,(b,c))</span><span>
</span><span id="line-145"></span><span>       </span><span class="hs-comment">--</span><span>
</span><span id="line-146"></span><span>       </span><span class="hs-comment">-- We also need to get the completely-unconstrained tyvars of</span><span>
</span><span id="line-147"></span><span>       </span><span class="hs-comment">-- the LHS, lest they otherwise get defaulted to Any; but we do that</span><span>
</span><span id="line-148"></span><span>       </span><span class="hs-comment">-- during zonking (see GHC.Tc.Utils.Zonk.zonkRule)</span><span>
</span><span id="line-149"></span><span>
</span><span id="line-150"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174983"><span class="annot"><span class="annottext">tpl_ids :: [TcTyVar]
</span><a href="#local-6989586621681174983"><span class="hs-identifier hs-var hs-var">tpl_ids</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174986"><span class="hs-identifier hs-var">lhs_evs</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174994"><span class="hs-identifier hs-var">id_bndrs</span></a></span><span>
</span><span id="line-151"></span><span>
</span><span id="line-152"></span><span>       </span><span class="hs-comment">-- See Note [Re-quantify type variables in rules]</span><span>
</span><span id="line-153"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174982"><span class="annot"><span class="annottext">CandidatesQTvs
</span><a href="#local-6989586621681174982"><span class="hs-identifier hs-var">forall_tkvs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TcType] -&gt; TcM CandidatesQTvs
</span><a href="GHC.Tc.Utils.TcMType.html#candidateQTyVarsOfTypes"><span class="hs-identifier hs-var">candidateQTyVarsOfTypes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174989"><span class="hs-identifier hs-var">rule_ty</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; [TcType] -&gt; [TcType]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">(TcTyVar -&gt; TcType) -&gt; [TcTyVar] -&gt; [TcType]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174983"><span class="hs-identifier hs-var">tpl_ids</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-154"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174979"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174979"><span class="hs-identifier hs-var">qtkvs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">CandidatesQTvs -&gt; TcM [TcTyVar]
</span><a href="GHC.Tc.Utils.TcMType.html#quantifyTyVars"><span class="hs-identifier hs-var">quantifyTyVars</span></a></span><span> </span><span class="annot"><span class="annottext">CandidatesQTvs
</span><a href="#local-6989586621681174982"><span class="hs-identifier hs-var">forall_tkvs</span></a></span><span>
</span><span id="line-155"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;tcRule&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[MsgDoc] -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName) -&gt; MsgDoc
</span><a href="GHC.Hs.Decls.html#pprFullRuleName"><span class="hs-identifier hs-var">pprFullRuleName</span></a></span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName)
</span><a href="#local-6989586621681175015"><span class="hs-identifier hs-var">rname</span></a></span><span>
</span><span id="line-156"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">CandidatesQTvs -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">CandidatesQTvs
</span><a href="#local-6989586621681174982"><span class="hs-identifier hs-var">forall_tkvs</span></a></span><span>
</span><span id="line-157"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174979"><span class="hs-identifier hs-var">qtkvs</span></a></span><span>
</span><span id="line-158"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174989"><span class="hs-identifier hs-var">rule_ty</span></a></span><span>
</span><span id="line-159"></span><span>                                </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[MsgDoc] -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174977"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc
</span><a href="GHC.Utils.Outputable.html#dcolon"><span class="hs-identifier hs-var">dcolon</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; TcType
</span><a href="GHC.Types.Id.html#idType"><span class="hs-identifier hs-var">idType</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174977"><span class="hs-identifier hs-var">id</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">|</span><span> </span><span id="local-6989586621681174977"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174977"><span class="hs-identifier hs-var">id</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174983"><span class="hs-identifier hs-var">tpl_ids</span></a></span><span> </span><span class="hs-special">]</span><span>
</span><span id="line-160"></span><span>                  </span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-161"></span><span>
</span><span id="line-162"></span><span>       </span><span class="hs-comment">-- SimplfyRule Plan, step 5</span><span>
</span><span id="line-163"></span><span>       </span><span class="hs-comment">-- Simplify the LHS and RHS constraints:</span><span>
</span><span id="line-164"></span><span>       </span><span class="hs-comment">-- For the LHS constraints we must solve the remaining constraints</span><span>
</span><span id="line-165"></span><span>       </span><span class="hs-comment">-- (a) so that we report insoluble ones</span><span>
</span><span id="line-166"></span><span>       </span><span class="hs-comment">-- (b) so that we bind any soluble ones</span><span>
</span><span id="line-167"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174974"><span class="annot"><span class="annottext">skol_info :: SkolemInfo
</span><a href="#local-6989586621681174974"><span class="hs-identifier hs-var hs-var">skol_info</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">RuleName -&gt; SkolemInfo
</span><a href="GHC.Tc.Types.Origin.html#RuleSkol"><span class="hs-identifier hs-var">RuleSkol</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681175013"><span class="hs-identifier hs-var">name</span></a></span><span>
</span><span id="line-168"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174972"><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174972"><span class="hs-identifier hs-var">lhs_implic</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174971"><span class="annot"><span class="annottext">TcEvBinds
</span><a href="#local-6989586621681174971"><span class="hs-identifier hs-var">lhs_binds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcLevel
-&gt; SkolemInfo
-&gt; [TcTyVar]
-&gt; [TcTyVar]
-&gt; WantedConstraints
-&gt; TcM (Bag Implication, TcEvBinds)
</span><a href="GHC.Tc.Utils.Unify.html#buildImplicationFor"><span class="hs-identifier hs-var">buildImplicationFor</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174998"><span class="hs-identifier hs-var">tc_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">SkolemInfo
</span><a href="#local-6989586621681174974"><span class="hs-identifier hs-var">skol_info</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174979"><span class="hs-identifier hs-var">qtkvs</span></a></span><span>
</span><span id="line-169"></span><span>                                         </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174986"><span class="hs-identifier hs-var">lhs_evs</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174985"><span class="hs-identifier hs-var">residual_lhs_wanted</span></a></span><span>
</span><span id="line-170"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174970"><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174970"><span class="hs-identifier hs-var">rhs_implic</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174969"><span class="annot"><span class="annottext">TcEvBinds
</span><a href="#local-6989586621681174969"><span class="hs-identifier hs-var">rhs_binds</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcLevel
-&gt; SkolemInfo
-&gt; [TcTyVar]
-&gt; [TcTyVar]
-&gt; WantedConstraints
-&gt; TcM (Bag Implication, TcEvBinds)
</span><a href="GHC.Tc.Utils.Unify.html#buildImplicationFor"><span class="hs-identifier hs-var">buildImplicationFor</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174998"><span class="hs-identifier hs-var">tc_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">SkolemInfo
</span><a href="#local-6989586621681174974"><span class="hs-identifier hs-var">skol_info</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174979"><span class="hs-identifier hs-var">qtkvs</span></a></span><span>
</span><span id="line-171"></span><span>                                         </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174986"><span class="hs-identifier hs-var">lhs_evs</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174990"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span>
</span><span id="line-172"></span><span>
</span><span id="line-173"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">Bag Implication -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#emitImplications"><span class="hs-identifier hs-var">emitImplications</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174972"><span class="hs-identifier hs-var">lhs_implic</span></a></span><span> </span><span class="annot"><span class="annottext">Bag Implication -&gt; Bag Implication -&gt; Bag Implication
forall a. Bag a -&gt; Bag a -&gt; Bag a
</span><a href="GHC.Data.Bag.html#unionBags"><span class="hs-operator hs-var">`unionBags`</span></a></span><span> </span><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174970"><span class="hs-identifier hs-var">rhs_implic</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-174"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">RuleDecl GhcTc -&gt; TcM (RuleDecl GhcTc)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">(RuleDecl GhcTc -&gt; TcM (RuleDecl GhcTc))
-&gt; RuleDecl GhcTc -&gt; TcM (RuleDecl GhcTc)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span> </span><span class="annot"><span class="annottext">HsRule :: forall pass.
XHsRule pass
-&gt; Located (SourceText, RuleName)
-&gt; Activation
-&gt; Maybe [LHsTyVarBndr () (NoGhcTc pass)]
-&gt; [LRuleBndr pass]
-&gt; Located (HsExpr pass)
-&gt; Located (HsExpr pass)
-&gt; RuleDecl pass
</span><a href="GHC.Hs.Decls.html#HsRule"><span class="hs-identifier hs-type">HsRule</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">rd_ext :: XHsRule GhcTc
</span><a href="GHC.Hs.Decls.html#rd_ext"><span class="hs-identifier hs-var">rd_ext</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">XHsRule GhcRn
XHsRule GhcTc
</span><a href="#local-6989586621681175017"><span class="hs-identifier hs-var">ext</span></a></span><span>
</span><span id="line-175"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_name :: Located (SourceText, RuleName)
</span><a href="GHC.Hs.Decls.html#rd_name"><span class="hs-identifier hs-var">rd_name</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Located (SourceText, RuleName)
</span><a href="#local-6989586621681175015"><span class="hs-identifier hs-var">rname</span></a></span><span>
</span><span id="line-176"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_act :: Activation
</span><a href="GHC.Hs.Decls.html#rd_act"><span class="hs-identifier hs-var">rd_act</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Activation
</span><a href="#local-6989586621681175011"><span class="hs-identifier hs-var">act</span></a></span><span>
</span><span id="line-177"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_tyvs :: Maybe [LHsTyVarBndr () (NoGhcTc GhcTc)]
</span><a href="GHC.Hs.Decls.html#rd_tyvs"><span class="hs-identifier hs-var">rd_tyvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () (NoGhcTc GhcRn)]
Maybe [LHsTyVarBndr () (NoGhcTc GhcTc)]
</span><a href="#local-6989586621681175009"><span class="hs-identifier hs-var">ty_bndrs</span></a></span><span> </span><span class="hs-comment">-- preserved for ppr-ing</span><span>
</span><span id="line-178"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_tmvs :: [LRuleBndr GhcTc]
</span><a href="GHC.Hs.Decls.html#rd_tmvs"><span class="hs-identifier hs-var">rd_tmvs</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(TcTyVar -&gt; LRuleBndr GhcTc) -&gt; [TcTyVar] -&gt; [LRuleBndr GhcTc]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleBndr GhcTc -&gt; LRuleBndr GhcTc
forall e. e -&gt; Located e
</span><a href="GHC.Types.SrcLoc.html#noLoc"><span class="hs-identifier hs-var">noLoc</span></a></span><span> </span><span class="annot"><span class="annottext">(RuleBndr GhcTc -&gt; LRuleBndr GhcTc)
-&gt; (TcTyVar -&gt; RuleBndr GhcTc) -&gt; TcTyVar -&gt; LRuleBndr GhcTc
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">XCRuleBndr GhcTc -&gt; Located (IdP GhcTc) -&gt; RuleBndr GhcTc
forall pass. XCRuleBndr pass -&gt; Located (IdP pass) -&gt; RuleBndr pass
</span><a href="GHC.Hs.Decls.html#RuleBndr"><span class="hs-identifier hs-var">RuleBndr</span></a></span><span> </span><span class="annot"><span class="annottext">NoExtField
XCRuleBndr GhcTc
</span><a href="GHC.Hs.Extension.html#noExtField"><span class="hs-identifier hs-var">noExtField</span></a></span><span> </span><span class="annot"><span class="annottext">(GenLocated SrcSpan TcTyVar -&gt; RuleBndr GhcTc)
-&gt; (TcTyVar -&gt; GenLocated SrcSpan TcTyVar)
-&gt; TcTyVar
-&gt; RuleBndr GhcTc
forall b c a. (b -&gt; c) -&gt; (a -&gt; b) -&gt; a -&gt; c
</span><a href="../../base/src/GHC.Base.html#."><span class="hs-operator hs-var">.</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; GenLocated SrcSpan TcTyVar
forall e. e -&gt; Located e
</span><a href="GHC.Types.SrcLoc.html#noLoc"><span class="hs-identifier hs-var">noLoc</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-179"></span><span>                                         </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174979"><span class="hs-identifier hs-var">qtkvs</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174983"><span class="hs-identifier hs-var">tpl_ids</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-180"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_lhs :: LHsExpr GhcTc
</span><a href="GHC.Hs.Decls.html#rd_lhs"><span class="hs-identifier hs-var">rd_lhs</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcEvBinds -&gt; LHsExpr GhcTc -&gt; LHsExpr GhcTc
</span><a href="GHC.Hs.Utils.html#mkHsDictLet"><span class="hs-identifier hs-var">mkHsDictLet</span></a></span><span> </span><span class="annot"><span class="annottext">TcEvBinds
</span><a href="#local-6989586621681174971"><span class="hs-identifier hs-var">lhs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174993"><span class="hs-identifier hs-var">lhs'</span></a></span><span>
</span><span id="line-181"></span><span>                         </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">rd_rhs :: LHsExpr GhcTc
</span><a href="GHC.Hs.Decls.html#rd_rhs"><span class="hs-identifier hs-var">rd_rhs</span></a></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcEvBinds -&gt; LHsExpr GhcTc -&gt; LHsExpr GhcTc
</span><a href="GHC.Hs.Utils.html#mkHsDictLet"><span class="hs-identifier hs-var">mkHsDictLet</span></a></span><span> </span><span class="annot"><span class="annottext">TcEvBinds
</span><a href="#local-6989586621681174969"><span class="hs-identifier hs-var">rhs_binds</span></a></span><span> </span><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174991"><span class="hs-identifier hs-var">rhs'</span></a></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-182"></span><span>
</span><span id="line-183"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#generateRuleConstraints"><span class="hs-identifier hs-type">generateRuleConstraints</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Type.html#LHsTyVarBndr"><span class="hs-identifier hs-type">LHsTyVarBndr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LRuleBndr"><span class="hs-identifier hs-type">LRuleBndr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-184"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Hs.Expr.html#LHsExpr"><span class="hs-identifier hs-type">LHsExpr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Hs.Expr.html#LHsExpr"><span class="hs-identifier hs-type">LHsExpr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span>
</span><span id="line-185"></span><span>                        </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Tc.Types.html#TcId"><span class="hs-identifier hs-type">TcId</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-186"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Hs.Expr.html#LHsExpr"><span class="hs-identifier hs-type">LHsExpr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span>
</span><span id="line-187"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Hs.Expr.html#LHsExpr"><span class="hs-identifier hs-type">LHsExpr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcTc"><span class="hs-identifier hs-type">GhcTc</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span>
</span><span id="line-188"></span><span>                               </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcType"><span class="hs-identifier hs-type">TcType</span></a></span><span> </span><span class="hs-special">)</span><span>
</span><span id="line-189"></span><span id="generateRuleConstraints"><span class="annot"><span class="annottext">generateRuleConstraints :: Maybe [LHsTyVarBndr () GhcRn]
-&gt; [LRuleBndr GhcRn]
-&gt; Located (HsExpr GhcRn)
-&gt; Located (HsExpr GhcRn)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
</span><a href="GHC.Tc.Gen.Rule.html#generateRuleConstraints"><span class="hs-identifier hs-var hs-var">generateRuleConstraints</span></a></span></span><span> </span><span id="local-6989586621681174961"><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
</span><a href="#local-6989586621681174961"><span class="hs-identifier hs-var">ty_bndrs</span></a></span></span><span> </span><span id="local-6989586621681174960"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174960"><span class="hs-identifier hs-var">tm_bndrs</span></a></span></span><span> </span><span id="local-6989586621681174959"><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681174959"><span class="hs-identifier hs-var">lhs</span></a></span></span><span> </span><span id="local-6989586621681174958"><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681174958"><span class="hs-identifier hs-var">rhs</span></a></span></span><span>
</span><span id="line-190"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621681174957"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174957"><span class="hs-identifier hs-var">tv_bndrs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174956"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174956"><span class="hs-identifier hs-var">id_bndrs</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174955"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174955"><span class="hs-identifier hs-var">bndr_wanted</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM ([TcTyVar], [TcTyVar])
-&gt; TcM (([TcTyVar], [TcTyVar]), WantedConstraints)
forall a. TcM a -&gt; TcM (a, WantedConstraints)
</span><a href="GHC.Tc.Utils.Monad.html#captureConstraints"><span class="hs-identifier hs-var">captureConstraints</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM ([TcTyVar], [TcTyVar])
 -&gt; TcM (([TcTyVar], [TcTyVar]), WantedConstraints))
-&gt; TcM ([TcTyVar], [TcTyVar])
-&gt; TcM (([TcTyVar], [TcTyVar]), WantedConstraints)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-191"></span><span>                                                </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
-&gt; [LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleBndrs"><span class="hs-identifier hs-var">tcRuleBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
</span><a href="#local-6989586621681174961"><span class="hs-identifier hs-var">ty_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174960"><span class="hs-identifier hs-var">tm_bndrs</span></a></span><span>
</span><span id="line-192"></span><span>              </span><span class="hs-comment">-- bndr_wanted constraints can include wildcard hole</span><span>
</span><span id="line-193"></span><span>              </span><span class="hs-comment">-- constraints, which we should not forget about.</span><span>
</span><span id="line-194"></span><span>              </span><span class="hs-comment">-- It may mention the skolem type variables bound by</span><span>
</span><span id="line-195"></span><span>              </span><span class="hs-comment">-- the RULE.  c.f. #10072</span><span>
</span><span id="line-196"></span><span>
</span><span id="line-197"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
forall r. [TcTyVar] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendTyVarEnv"><span class="hs-identifier hs-var">tcExtendTyVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174957"><span class="hs-identifier hs-var">tv_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM
   ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
    WantedConstraints, TcType)
 -&gt; TcM
      ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
       WantedConstraints, TcType))
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-198"></span><span>         </span><span class="annot"><span class="annottext">[TcTyVar]
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
forall r. [TcTyVar] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendIdEnv"><span class="hs-identifier hs-var">tcExtendIdEnv</span></a></span><span>    </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174956"><span class="hs-identifier hs-var">id_bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM
   ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
    WantedConstraints, TcType)
 -&gt; TcM
      ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
       WantedConstraints, TcType))
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-199"></span><span>    </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-comment">-- See Note [Solve order for RULES]</span><span>
</span><span id="line-200"></span><span>         </span><span class="hs-special">(</span><span class="hs-special">(</span><span id="local-6989586621681174950"><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174950"><span class="hs-identifier hs-var">lhs'</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174949"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174949"><span class="hs-identifier hs-var">rule_ty</span></a></span></span><span class="hs-special">)</span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174948"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174948"><span class="hs-identifier hs-var">lhs_wanted</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM (LHsExpr GhcTc, TcType)
-&gt; TcM ((LHsExpr GhcTc, TcType), WantedConstraints)
forall a. TcM a -&gt; TcM (a, WantedConstraints)
</span><a href="GHC.Tc.Utils.Monad.html#captureConstraints"><span class="hs-identifier hs-var">captureConstraints</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Located (HsExpr GhcRn) -&gt; TcM (LHsExpr GhcTc, TcType)
</span><a href="GHC.Tc.Gen.Expr.html#tcInferRho"><span class="hs-identifier hs-var">tcInferRho</span></a></span><span> </span><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681174959"><span class="hs-identifier hs-var">lhs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-201"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174946"><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174946"><span class="hs-identifier hs-var">rhs'</span></a></span></span><span class="hs-special">,</span><span>            </span><span id="local-6989586621681174945"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174945"><span class="hs-identifier hs-var">rhs_wanted</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM (LHsExpr GhcTc) -&gt; TcM (LHsExpr GhcTc, WantedConstraints)
forall a. TcM a -&gt; TcM (a, WantedConstraints)
</span><a href="GHC.Tc.Utils.Monad.html#captureConstraints"><span class="hs-identifier hs-var">captureConstraints</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM (LHsExpr GhcTc) -&gt; TcM (LHsExpr GhcTc, WantedConstraints))
-&gt; TcM (LHsExpr GhcTc) -&gt; TcM (LHsExpr GhcTc, WantedConstraints)
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-202"></span><span>                                          </span><span class="annot"><span class="annottext">Located (HsExpr GhcRn) -&gt; TcType -&gt; TcM (LHsExpr GhcTc)
</span><a href="GHC.Tc.Gen.Expr.html#tcCheckMonoExpr"><span class="hs-identifier hs-var">tcCheckMonoExpr</span></a></span><span> </span><span class="annot"><span class="annottext">Located (HsExpr GhcRn)
</span><a href="#local-6989586621681174958"><span class="hs-identifier hs-var">rhs</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174949"><span class="hs-identifier hs-var">rule_ty</span></a></span><span>
</span><span id="line-203"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174943"><span class="annot"><span class="annottext">all_lhs_wanted :: WantedConstraints
</span><a href="#local-6989586621681174943"><span class="hs-identifier hs-var hs-var">all_lhs_wanted</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174955"><span class="hs-identifier hs-var">bndr_wanted</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; WantedConstraints -&gt; WantedConstraints
</span><a href="GHC.Tc.Types.Constraint.html#andWC"><span class="hs-operator hs-var">`andWC`</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174948"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-204"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
 WantedConstraints, TcType)
-&gt; TcM
     ([TcTyVar], LHsExpr GhcTc, WantedConstraints, LHsExpr GhcTc,
      WantedConstraints, TcType)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174956"><span class="hs-identifier hs-var">id_bndrs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174950"><span class="hs-identifier hs-var">lhs'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174943"><span class="hs-identifier hs-var">all_lhs_wanted</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">LHsExpr GhcTc
</span><a href="#local-6989586621681174946"><span class="hs-identifier hs-var">rhs'</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174945"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174949"><span class="hs-identifier hs-var">rule_ty</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-205"></span><span>
</span><span id="line-206"></span><span class="hs-comment">-- See Note [TcLevel in type checking rules]</span><span>
</span><span id="line-207"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleBndrs"><span class="hs-identifier hs-type">tcRuleBndrs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Maybe"><span class="hs-identifier hs-type">Maybe</span></a></span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Type.html#LHsTyVarBndr"><span class="hs-identifier hs-type">LHsTyVarBndr</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LRuleBndr"><span class="hs-identifier hs-type">LRuleBndr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span>
</span><span id="line-208"></span><span>            </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-209"></span><span id="tcRuleBndrs"><span class="annot"><span class="annottext">tcRuleBndrs :: Maybe [LHsTyVarBndr () GhcRn]
-&gt; [LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleBndrs"><span class="hs-identifier hs-var hs-var">tcRuleBndrs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681174940"><span class="annot"><span class="annottext">[LHsTyVarBndr () GhcRn]
</span><a href="#local-6989586621681174940"><span class="hs-identifier hs-var">bndrs</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681174939"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174939"><span class="hs-identifier hs-var">xs</span></a></span></span><span>
</span><span id="line-210"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174938"><span class="annot"><span class="annottext">[VarBndr TcTyVar ()]
</span><a href="#local-6989586621681174938"><span class="hs-identifier hs-var">tybndrs1</span></a></span></span><span class="hs-special">,</span><span class="hs-special">(</span><span id="local-6989586621681174937"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174937"><span class="hs-identifier hs-var">tys2</span></a></span></span><span class="hs-special">,</span><span id="local-6989586621681174936"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174936"><span class="hs-identifier hs-var">tms</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[LHsTyVarBndr () GhcRn]
-&gt; TcM ([TcTyVar], [TcTyVar])
-&gt; TcM ([VarBndr TcTyVar ()], ([TcTyVar], [TcTyVar]))
forall flag a.
OutputableBndrFlag flag =&gt;
[LHsTyVarBndr flag GhcRn]
-&gt; TcM a -&gt; TcM ([VarBndr TcTyVar flag], a)
</span><a href="GHC.Tc.Gen.HsType.html#bindExplicitTKBndrs_Skol"><span class="hs-identifier hs-var">bindExplicitTKBndrs_Skol</span></a></span><span> </span><span class="annot"><span class="annottext">[LHsTyVarBndr () GhcRn]
</span><a href="#local-6989586621681174940"><span class="hs-identifier hs-var">bndrs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM ([TcTyVar], [TcTyVar])
 -&gt; TcM ([VarBndr TcTyVar ()], ([TcTyVar], [TcTyVar])))
-&gt; TcM ([TcTyVar], [TcTyVar])
-&gt; TcM ([VarBndr TcTyVar ()], ([TcTyVar], [TcTyVar]))
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-211"></span><span>                                  </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174939"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-212"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174933"><span class="annot"><span class="annottext">tys1 :: [TcTyVar]
</span><a href="#local-6989586621681174933"><span class="hs-identifier hs-var hs-var">tys1</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[VarBndr TcTyVar ()] -&gt; [TcTyVar]
forall tv argf. [VarBndr tv argf] -&gt; [tv]
</span><a href="GHC.Types.Var.html#binderVars"><span class="hs-identifier hs-var">binderVars</span></a></span><span> </span><span class="annot"><span class="annottext">[VarBndr TcTyVar ()]
</span><a href="#local-6989586621681174938"><span class="hs-identifier hs-var">tybndrs1</span></a></span><span>
</span><span id="line-213"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174933"><span class="hs-identifier hs-var">tys1</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174937"><span class="hs-identifier hs-var">tys2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174936"><span class="hs-identifier hs-var">tms</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-214"></span><span>
</span><span id="line-215"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleBndrs"><span class="hs-identifier hs-var">tcRuleBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">Maybe [LHsTyVarBndr () GhcRn]
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span id="local-6989586621681174931"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174931"><span class="hs-identifier hs-var">xs</span></a></span></span><span>
</span><span id="line-216"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174931"><span class="hs-identifier hs-var">xs</span></a></span><span>
</span><span id="line-217"></span><span>
</span><span id="line-218"></span><span class="hs-comment">-- See Note [TcLevel in type checking rules]</span><span>
</span><span id="line-219"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-type">tcRuleTmBndrs</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Hs.Decls.html#LRuleBndr"><span class="hs-identifier hs-type">LRuleBndr</span></a></span><span> </span><span class="annot"><a href="GHC.Hs.Extension.html#GhcRn"><span class="hs-identifier hs-type">GhcRn</span></a></span><span class="hs-special">]</span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#TcTyVar"><span class="hs-identifier hs-type">TcTyVar</span></a></span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#Id"><span class="hs-identifier hs-type">Id</span></a></span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-220"></span><span id="tcRuleTmBndrs"><span class="annot"><span class="annottext">tcRuleTmBndrs :: [LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var hs-var">tcRuleTmBndrs</span></a></span></span><span> </span><span class="hs-special">[</span><span class="hs-special">]</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">,</span><span class="hs-special">[</span><span class="hs-special">]</span><span class="hs-special">)</span><span>
</span><span id="line-221"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#RuleBndr"><span class="hs-identifier hs-type">RuleBndr</span></a></span><span> </span><span class="annot"><span class="annottext">XCRuleBndr GhcRn
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681174930"><span class="annot"><span class="annottext">IdP GhcRn
</span><a href="#local-6989586621681174930"><span class="hs-identifier hs-var">name</span></a></span></span><span class="hs-special">)</span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621681174929"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174929"><span class="hs-identifier hs-var">rule_bndrs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-222"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681174928"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174928"><span class="hs-identifier hs-var">ty</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcM TcType
</span><a href="GHC.Tc.Utils.TcMType.html#newOpenFlexiTyVarTy"><span class="hs-identifier hs-var">newOpenFlexiTyVarTy</span></a></span><span>
</span><span id="line-223"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174926"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174926"><span class="hs-identifier hs-var">tyvars</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174925"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174925"><span class="hs-identifier hs-var">tmvars</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174929"><span class="hs-identifier hs-var">rule_bndrs</span></a></span><span>
</span><span id="line-224"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174926"><span class="hs-identifier hs-var">tyvars</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Name -&gt; TcType -&gt; TcType -&gt; TcTyVar
Name -&gt; TcType -&gt; TcType -&gt; TcTyVar
</span><a href="GHC.Types.Id.html#mkLocalId"><span class="hs-identifier hs-var">mkLocalId</span></a></span><span> </span><span class="annot"><span class="annottext">Name
IdP GhcRn
</span><a href="#local-6989586621681174930"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="GHC.Core.Type.html#Many"><span class="hs-identifier hs-var">Many</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174928"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174925"><span class="hs-identifier hs-var">tmvars</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-225"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Hs.Decls.html#RuleBndrSig"><span class="hs-identifier hs-type">RuleBndrSig</span></a></span><span> </span><span class="annot"><span class="annottext">XRuleBndrSig GhcRn
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Types.SrcLoc.html#L"><span class="hs-identifier hs-type">L</span></a></span><span> </span><span class="annot"><span class="annottext">SrcSpan
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681174921"><span class="annot"><span class="annottext">IdP GhcRn
</span><a href="#local-6989586621681174921"><span class="hs-identifier hs-var">name</span></a></span></span><span class="hs-special">)</span><span> </span><span id="local-6989586621681174920"><span class="annot"><span class="annottext">HsPatSigType GhcRn
</span><a href="#local-6989586621681174920"><span class="hs-identifier hs-var">rn_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="hs-glyph hs-type">:</span></span><span> </span><span id="local-6989586621681174919"><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174919"><span class="hs-identifier hs-var">rule_bndrs</span></a></span></span><span class="hs-special">)</span><span>
</span><span id="line-226"></span><span class="hs-comment">--  e.g         x :: a-&gt;a</span><span>
</span><span id="line-227"></span><span class="hs-comment">--  The tyvar 'a' is brought into scope first, just as if you'd written</span><span>
</span><span id="line-228"></span><span class="hs-comment">--              a::*, x :: a-&gt;a</span><span>
</span><span id="line-229"></span><span class="hs-comment">--  If there's an explicit forall, the renamer would have already reported an</span><span>
</span><span id="line-230"></span><span class="hs-comment">--   error for each out-of-scope type variable used</span><span>
</span><span id="line-231"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span>  </span><span class="hs-special">{</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174918"><span class="annot"><span class="annottext">ctxt :: UserTypeCtxt
</span><a href="#local-6989586621681174918"><span class="hs-identifier hs-var hs-var">ctxt</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Name -&gt; UserTypeCtxt
</span><a href="GHC.Tc.Types.Origin.html#RuleSigCtxt"><span class="hs-identifier hs-var">RuleSigCtxt</span></a></span><span> </span><span class="annot"><span class="annottext">Name
IdP GhcRn
</span><a href="#local-6989586621681174921"><span class="hs-identifier hs-var">name</span></a></span><span>
</span><span id="line-232"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[(Name, TcTyVar)]
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174916"><span class="annot"><span class="annottext">[(Name, TcTyVar)]
</span><a href="#local-6989586621681174916"><span class="hs-identifier hs-var">tvs</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174915"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174915"><span class="hs-identifier hs-var">id_ty</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
-&gt; HsPatSigType GhcRn
-&gt; TcM ([(Name, TcTyVar)], [(Name, TcTyVar)], TcType)
</span><a href="GHC.Tc.Gen.HsType.html#tcHsPatSigType"><span class="hs-identifier hs-var">tcHsPatSigType</span></a></span><span> </span><span class="annot"><span class="annottext">UserTypeCtxt
</span><a href="#local-6989586621681174918"><span class="hs-identifier hs-var">ctxt</span></a></span><span> </span><span class="annot"><span class="annottext">HsPatSigType GhcRn
</span><a href="#local-6989586621681174920"><span class="hs-identifier hs-var">rn_ty</span></a></span><span>
</span><span id="line-233"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span id="local-6989586621681174913"><span class="annot"><span class="annottext">id :: TcTyVar
</span><a href="#local-6989586621681174913"><span class="hs-identifier hs-var hs-var">id</span></a></span></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; Name -&gt; TcType -&gt; TcType -&gt; TcTyVar
Name -&gt; TcType -&gt; TcType -&gt; TcTyVar
</span><a href="GHC.Types.Id.html#mkLocalId"><span class="hs-identifier hs-var">mkLocalId</span></a></span><span> </span><span class="annot"><span class="annottext">Name
IdP GhcRn
</span><a href="#local-6989586621681174921"><span class="hs-identifier hs-var">name</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="GHC.Core.Type.html#Many"><span class="hs-identifier hs-var">Many</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174915"><span class="hs-identifier hs-var">id_ty</span></a></span><span>
</span><span id="line-234"></span><span>                    </span><span class="hs-comment">-- See Note [Typechecking pattern signature binders] in GHC.Tc.Gen.HsType</span><span>
</span><span id="line-235"></span><span>
</span><span id="line-236"></span><span>              </span><span class="hs-comment">-- The type variables scope over subsequent bindings; yuk</span><span>
</span><span id="line-237"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174912"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174912"><span class="hs-identifier hs-var">tyvars</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174911"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174911"><span class="hs-identifier hs-var">tmvars</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">[(Name, TcTyVar)]
-&gt; TcM ([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall r. [(Name, TcTyVar)] -&gt; TcM r -&gt; TcM r
</span><a href="GHC.Tc.Utils.Env.html#tcExtendNameTyVarEnv"><span class="hs-identifier hs-var">tcExtendNameTyVarEnv</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TcTyVar)]
</span><a href="#local-6989586621681174916"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">(TcM ([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar]))
-&gt; TcM ([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-238"></span><span>                                   </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn] -&gt; TcM ([TcTyVar], [TcTyVar])
</span><a href="GHC.Tc.Gen.Rule.html#tcRuleTmBndrs"><span class="hs-identifier hs-var">tcRuleTmBndrs</span></a></span><span> </span><span class="annot"><span class="annottext">[LRuleBndr GhcRn]
</span><a href="#local-6989586621681174919"><span class="hs-identifier hs-var">rule_bndrs</span></a></span><span>
</span><span id="line-239"></span><span>        </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], [TcTyVar]) -&gt; TcM ([TcTyVar], [TcTyVar])
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">((Name, TcTyVar) -&gt; TcTyVar) -&gt; [(Name, TcTyVar)] -&gt; [TcTyVar]
forall a b. (a -&gt; b) -&gt; [a] -&gt; [b]
</span><a href="../../base/src/GHC.Base.html#map"><span class="hs-identifier hs-var">map</span></a></span><span> </span><span class="annot"><span class="annottext">(Name, TcTyVar) -&gt; TcTyVar
forall a b. (a, b) -&gt; b
</span><a href="../../base/src/Data.Tuple.html#snd"><span class="hs-identifier hs-var">snd</span></a></span><span> </span><span class="annot"><span class="annottext">[(Name, TcTyVar)]
</span><a href="#local-6989586621681174916"><span class="hs-identifier hs-var">tvs</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar] -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. [a] -&gt; [a] -&gt; [a]
</span><a href="../../base/src/GHC.Base.html#%2B%2B"><span class="hs-operator hs-var">++</span></a></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174912"><span class="hs-identifier hs-var">tyvars</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174913"><span class="hs-identifier hs-var">id</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; [TcTyVar] -&gt; [TcTyVar]
forall a. a -&gt; [a] -&gt; [a]
</span><span class="hs-glyph hs-var">:</span></span><span> </span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174911"><span class="hs-identifier hs-var">tmvars</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-240"></span><span>
</span><span id="line-241"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#ruleCtxt"><span class="hs-identifier hs-type">ruleCtxt</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Data.FastString.html#FastString"><span class="hs-identifier hs-type">FastString</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Utils.Outputable.html#SDoc"><span class="hs-identifier hs-type">SDoc</span></a></span><span>
</span><span id="line-242"></span><span id="ruleCtxt"><span class="annot"><span class="annottext">ruleCtxt :: RuleName -&gt; MsgDoc
</span><a href="GHC.Tc.Gen.Rule.html#ruleCtxt"><span class="hs-identifier hs-var hs-var">ruleCtxt</span></a></span></span><span> </span><span id="local-6989586621681174907"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681174907"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;When checking the rewrite rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span>
</span><span id="line-243"></span><span>                </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#doubleQuotes"><span class="hs-identifier hs-var">doubleQuotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ftext"><span class="hs-identifier hs-var">ftext</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681174907"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-244"></span><span>
</span><span id="line-245"></span><span>
</span><span id="line-246"></span><span class="hs-comment">{-
*********************************************************************************
*                                                                                 *
              Constraint simplification for rules
*                                                                                 *
***********************************************************************************

Note [The SimplifyRule Plan]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Example.  Consider the following left-hand side of a rule
        f (x == y) (y &gt; z) = ...
If we typecheck this expression we get constraints
        d1 :: Ord a, d2 :: Eq a
We do NOT want to &quot;simplify&quot; to the LHS
        forall x::a, y::a, z::a, d1::Ord a.
          f ((==) (eqFromOrd d1) x y) ((&gt;) d1 y z) = ...
Instead we want
        forall x::a, y::a, z::a, d1::Ord a, d2::Eq a.
          f ((==) d2 x y) ((&gt;) d1 y z) = ...

Here is another example:
        fromIntegral :: (Integral a, Num b) =&gt; a -&gt; b
        {-# RULES &quot;foo&quot;  fromIntegral = id :: Int -&gt; Int #-}
In the rule, a=b=Int, and Num Int is a superclass of Integral Int. But
we *dont* want to get
        forall dIntegralInt.
           fromIntegral Int Int dIntegralInt (scsel dIntegralInt) = id Int
because the scsel will mess up RULE matching.  Instead we want
        forall dIntegralInt, dNumInt.
          fromIntegral Int Int dIntegralInt dNumInt = id Int

Even if we have
        g (x == y) (y == z) = ..
where the two dictionaries are *identical*, we do NOT WANT
        forall x::a, y::a, z::a, d1::Eq a
          f ((==) d1 x y) ((&gt;) d1 y z) = ...
because that will only match if the dict args are (visibly) equal.
Instead we want to quantify over the dictionaries separately.

In short, simplifyRuleLhs must *only* squash equalities, leaving
all dicts unchanged, with absolutely no sharing.

Also note that we can't solve the LHS constraints in isolation:
Example   foo :: Ord a =&gt; a -&gt; a
          foo_spec :: Int -&gt; Int
          {-# RULE &quot;foo&quot;  foo = foo_spec #-}
Here, it's the RHS that fixes the type variable

HOWEVER, under a nested implication things are different
Consider
  f :: (forall a. Eq a =&gt; a-&gt;a) -&gt; Bool -&gt; ...
  {-# RULES &quot;foo&quot; forall (v::forall b. Eq b =&gt; b-&gt;b).
       f b True = ...
    #-}
Here we *must* solve the wanted (Eq a) from the given (Eq a)
resulting from skolemising the argument type of g.  So we
revert to SimplCheck when going under an implication.


--------- So the SimplifyRule Plan is this -----------------------

* Step 0: typecheck the LHS and RHS to get constraints from each

* Step 1: Simplify the LHS and RHS constraints all together in one bag
          We do this to discover all unification equalities

* Step 2: Zonk the ORIGINAL (unsimplified) LHS constraints, to take
          advantage of those unifications

* Setp 3: Partition the LHS constraints into the ones we will
          quantify over, and the others.
          See Note [RULE quantification over equalities]

* Step 4: Decide on the type variables to quantify over

* Step 5: Simplify the LHS and RHS constraints separately, using the
          quantified constraints as givens

Note [Solve order for RULES]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
In step 1 above, we need to be a bit careful about solve order.
Consider
   f :: Int -&gt; T Int
   type instance T Int = Bool

   RULE f 3 = True

From the RULE we get
   lhs-constraints:  T Int ~ alpha
   rhs-constraints:  Bool ~ alpha
where 'alpha' is the type that connects the two.  If we glom them
all together, and solve the RHS constraint first, we might solve
with alpha := Bool.  But then we'd end up with a RULE like

    RULE: f 3 |&gt; (co :: T Int ~ Bool) = True

which is terrible.  We want

    RULE: f 3 = True |&gt; (sym co :: Bool ~ T Int)

So we are careful to solve the LHS constraints first, and *then* the
RHS constraints.  Actually much of this is done by the on-the-fly
constraint solving, so the same order must be observed in
tcRule.


Note [RULE quantification over equalities]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Deciding which equalities to quantify over is tricky:
 * We do not want to quantify over insoluble equalities (Int ~ Bool)
    (a) because we prefer to report a LHS type error
    (b) because if such things end up in 'givens' we get a bogus
        &quot;inaccessible code&quot; error

 * But we do want to quantify over things like (a ~ F b), where
   F is a type function.

The difficulty is that it's hard to tell what is insoluble!
So we see whether the simplification step yielded any type errors,
and if so refrain from quantifying over *any* equalities.

Note [Quantifying over coercion holes]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Equality constraints from the LHS will emit coercion hole Wanteds.
These don't have a name, so we can't quantify over them directly.
Instead, because we really do want to quantify here, invent a new
EvVar for the coercion, fill the hole with the invented EvVar, and
then quantify over the EvVar. Not too tricky -- just some
impedance matching, really.

Note [Simplify cloned constraints]
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
At this stage, we're simplifying constraints only for insolubility
and for unification. Note that all the evidence is quickly discarded.
We use a clone of the real constraint. If we don't do this,
then RHS coercion-hole constraints get filled in, only to get filled
in *again* when solving the implications emitted from tcRule. That's
terrible, so we avoid the problem by cloning the constraints.

-}</span><span>
</span><span id="line-386"></span><span>
</span><span id="line-387"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#simplifyRule"><span class="hs-identifier hs-type">simplifyRule</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Types.Basic.html#RuleName"><span class="hs-identifier hs-type">RuleName</span></a></span><span>
</span><span id="line-388"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcLevel"><span class="hs-identifier hs-type">TcLevel</span></a></span><span>                 </span><span class="hs-comment">-- Level at which to solve the constraints</span><span>
</span><span id="line-389"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span>       </span><span class="hs-comment">-- Constraints from LHS</span><span>
</span><span id="line-390"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span>       </span><span class="hs-comment">-- Constraints from RHS</span><span>
</span><span id="line-391"></span><span>             </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="hs-special">(</span><span> </span><span class="hs-special">[</span><span class="annot"><a href="GHC.Types.Var.html#EvVar"><span class="hs-identifier hs-type">EvVar</span></a></span><span class="hs-special">]</span><span>               </span><span class="hs-comment">-- Quantify over these LHS vars</span><span>
</span><span id="line-392"></span><span>                    </span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span class="hs-special">)</span><span>    </span><span class="hs-comment">-- Residual un-quantified LHS constraints</span><span>
</span><span id="line-393"></span><span class="hs-comment">-- See Note [The SimplifyRule Plan]</span><span>
</span><span id="line-394"></span><span class="hs-comment">-- NB: This consumes all simple constraints on the LHS, but not</span><span>
</span><span id="line-395"></span><span class="hs-comment">-- any LHS implication constraints.</span><span>
</span><span id="line-396"></span><span id="simplifyRule"><span class="annot"><span class="annottext">simplifyRule :: RuleName
-&gt; TcLevel
-&gt; WantedConstraints
-&gt; WantedConstraints
-&gt; TcM ([TcTyVar], WantedConstraints)
</span><a href="GHC.Tc.Gen.Rule.html#simplifyRule"><span class="hs-identifier hs-var hs-var">simplifyRule</span></a></span></span><span> </span><span id="local-6989586621681174903"><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681174903"><span class="hs-identifier hs-var">name</span></a></span></span><span> </span><span id="local-6989586621681174902"><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174902"><span class="hs-identifier hs-var">tc_lvl</span></a></span></span><span> </span><span id="local-6989586621681174901"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174901"><span class="hs-identifier hs-var">lhs_wanted</span></a></span></span><span> </span><span id="local-6989586621681174900"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174900"><span class="hs-identifier hs-var">rhs_wanted</span></a></span></span><span>
</span><span id="line-397"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span>
</span><span id="line-398"></span><span>       </span><span class="hs-comment">-- Note [The SimplifyRule Plan] step 1</span><span>
</span><span id="line-399"></span><span>       </span><span class="hs-comment">-- First solve the LHS and *then* solve the RHS</span><span>
</span><span id="line-400"></span><span>       </span><span class="hs-comment">-- Crucially, this performs unifications</span><span>
</span><span id="line-401"></span><span>       </span><span class="hs-comment">-- Why clone?  See Note [Simplify cloned constraints]</span><span>
</span><span id="line-402"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174899"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174899"><span class="hs-identifier hs-var">lhs_clone</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; TcM WantedConstraints
</span><a href="GHC.Tc.Utils.TcMType.html#cloneWC"><span class="hs-identifier hs-var">cloneWC</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174901"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-403"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174897"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174897"><span class="hs-identifier hs-var">rhs_clone</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; TcM WantedConstraints
</span><a href="GHC.Tc.Utils.TcMType.html#cloneWC"><span class="hs-identifier hs-var">cloneWC</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174900"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span>
</span><span id="line-404"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcLevel -&gt; TcRn () -&gt; TcRn ()
forall a. TcLevel -&gt; TcM a -&gt; TcM a
</span><a href="GHC.Tc.Utils.Monad.html#setTcLevel"><span class="hs-identifier hs-var">setTcLevel</span></a></span><span> </span><span class="annot"><span class="annottext">TcLevel
</span><a href="#local-6989586621681174902"><span class="hs-identifier hs-var">tc_lvl</span></a></span><span> </span><span class="annot"><span class="annottext">(TcRn () -&gt; TcRn ()) -&gt; TcRn () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-405"></span><span>         </span><span class="annot"><span class="annottext">TcS () -&gt; TcRn ()
forall a. TcS a -&gt; TcM a
</span><a href="GHC.Tc.Solver.Monad.html#runTcSDeriveds"><span class="hs-identifier hs-var">runTcSDeriveds</span></a></span><span>    </span><span class="annot"><span class="annottext">(TcS () -&gt; TcRn ()) -&gt; TcS () -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-406"></span><span>         </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; TcS WantedConstraints
</span><a href="GHC.Tc.Solver.html#solveWanteds"><span class="hs-identifier hs-var">solveWanteds</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174899"><span class="hs-identifier hs-var">lhs_clone</span></a></span><span>
</span><span id="line-407"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><span class="hs-identifier">_</span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; TcS WantedConstraints
</span><a href="GHC.Tc.Solver.html#solveWanteds"><span class="hs-identifier hs-var">solveWanteds</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174897"><span class="hs-identifier hs-var">rhs_clone</span></a></span><span>
</span><span id="line-408"></span><span>                  </span><span class="hs-comment">-- Why do them separately?</span><span>
</span><span id="line-409"></span><span>                  </span><span class="hs-comment">-- See Note [Solve order for RULES]</span><span>
</span><span id="line-410"></span><span>            </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">() -&gt; TcS ()
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-411"></span><span>
</span><span id="line-412"></span><span>       </span><span class="hs-comment">-- Note [The SimplifyRule Plan] step 2</span><span>
</span><span id="line-413"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174893"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174893"><span class="hs-identifier hs-var">lhs_wanted</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; TcM WantedConstraints
</span><a href="GHC.Tc.Utils.TcMType.html#zonkWC"><span class="hs-identifier hs-var">zonkWC</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174901"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-414"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="hs-keyword">let</span><span> </span><span class="hs-special">(</span><span id="local-6989586621681174891"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174891"><span class="hs-identifier hs-var">quant_cts</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174890"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174890"><span class="hs-identifier hs-var">residual_lhs_wanted</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; (Cts, WantedConstraints)
</span><a href="GHC.Tc.Gen.Rule.html#getRuleQuantCts"><span class="hs-identifier hs-var">getRuleQuantCts</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174893"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-415"></span><span>
</span><span id="line-416"></span><span>       </span><span class="hs-comment">-- Note [The SimplifyRule Plan] step 3</span><span>
</span><span id="line-417"></span><span>       </span><span class="hs-special">;</span><span> </span><span id="local-6989586621681174888"><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174888"><span class="hs-identifier hs-var">quant_evs</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar)
-&gt; [Ct] -&gt; TcM [TcTyVar]
forall (t :: * -&gt; *) (m :: * -&gt; *) a b.
(Traversable t, Monad m) =&gt;
(a -&gt; m b) -&gt; t a -&gt; m (t b)
</span><a href="../../base/src/Data.Traversable.html#mapM"><span class="hs-identifier hs-var">mapM</span></a></span><span> </span><span class="annot"><span class="annottext">Ct -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
</span><a href="#local-6989586621681174887"><span class="hs-identifier hs-var">mk_quant_ev</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts -&gt; [Ct]
forall a. Bag a -&gt; [a]
</span><a href="GHC.Data.Bag.html#bagToList"><span class="hs-identifier hs-var">bagToList</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174891"><span class="hs-identifier hs-var">quant_cts</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-418"></span><span>
</span><span id="line-419"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.Monad.html#traceTc"><span class="hs-identifier hs-var">traceTc</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;simplifyRule&quot;</span></span><span> </span><span class="annot"><span class="annottext">(MsgDoc -&gt; TcRn ()) -&gt; MsgDoc -&gt; TcRn ()
forall a b. (a -&gt; b) -&gt; a -&gt; b
</span><a href="../../base/src/GHC.Base.html#%24"><span class="hs-operator hs-var">$</span></a></span><span>
</span><span id="line-420"></span><span>         </span><span class="annot"><span class="annottext">[MsgDoc] -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#vcat"><span class="hs-identifier hs-var">vcat</span></a></span><span> </span><span class="hs-special">[</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;LHS of rule&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#doubleQuotes"><span class="hs-identifier hs-var">doubleQuotes</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">RuleName -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ftext"><span class="hs-identifier hs-var">ftext</span></a></span><span> </span><span class="annot"><span class="annottext">RuleName
</span><a href="#local-6989586621681174903"><span class="hs-identifier hs-var">name</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-421"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;lhs_wanted&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174893"><span class="hs-identifier hs-var">lhs_wanted</span></a></span><span>
</span><span id="line-422"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;rhs_wanted&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174900"><span class="hs-identifier hs-var">rhs_wanted</span></a></span><span>
</span><span id="line-423"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;quant_cts&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174891"><span class="hs-identifier hs-var">quant_cts</span></a></span><span>
</span><span id="line-424"></span><span>              </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#text"><span class="hs-identifier hs-var">text</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;residual_lhs_wanted&quot;</span></span><span> </span><span class="annot"><span class="annottext">MsgDoc -&gt; MsgDoc -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#%3C%2B%3E"><span class="hs-operator hs-var">&lt;+&gt;</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174890"><span class="hs-identifier hs-var">residual_lhs_wanted</span></a></span><span>
</span><span id="line-425"></span><span>              </span><span class="hs-special">]</span><span>
</span><span id="line-426"></span><span>
</span><span id="line-427"></span><span>       </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">([TcTyVar], WantedConstraints)
-&gt; TcM ([TcTyVar], WantedConstraints)
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">[TcTyVar]
</span><a href="#local-6989586621681174888"><span class="hs-identifier hs-var">quant_evs</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174890"><span class="hs-identifier hs-var">residual_lhs_wanted</span></a></span><span class="hs-special">)</span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-428"></span><span>
</span><span id="line-429"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-430"></span><span>    </span><span class="annot"><a href="#local-6989586621681174887"><span class="hs-identifier hs-type">mk_quant_ev</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.html#TcM"><span class="hs-identifier hs-type">TcM</span></a></span><span> </span><span class="annot"><a href="GHC.Types.Var.html#EvVar"><span class="hs-identifier hs-type">EvVar</span></a></span><span>
</span><span id="line-431"></span><span>    </span><span id="local-6989586621681174887"><span class="annot"><span class="annottext">mk_quant_ev :: Ct -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
</span><a href="#local-6989586621681174887"><span class="hs-identifier hs-var hs-var">mk_quant_ev</span></a></span></span><span> </span><span id="local-6989586621681174885"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174885"><span class="hs-identifier hs-var">ct</span></a></span></span><span>
</span><span id="line-432"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#CtWanted"><span class="hs-identifier hs-type">CtWanted</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ctev_dest :: CtEvidence -&gt; TcEvDest
</span><a href="GHC.Tc.Types.Constraint.html#ctev_dest"><span class="hs-identifier hs-var">ctev_dest</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681174882"><span class="annot"><span class="annottext">TcEvDest
</span><a href="#local-6989586621681174882"><span class="hs-identifier hs-var">dest</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">ctev_pred :: CtEvidence -&gt; TcType
</span><a href="GHC.Tc.Types.Constraint.html#ctev_pred"><span class="hs-identifier hs-var">ctev_pred</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681174880"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174880"><span class="hs-identifier hs-var">pred</span></a></span></span><span> </span><span class="hs-special">}</span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">Ct -&gt; CtEvidence
</span><a href="GHC.Tc.Types.Constraint.html#ctEvidence"><span class="hs-identifier hs-var">ctEvidence</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174885"><span class="hs-identifier hs-var">ct</span></a></span><span>
</span><span id="line-433"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TcEvDest
</span><a href="#local-6989586621681174882"><span class="hs-identifier hs-var">dest</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-434"></span><span>          </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#EvVarDest"><span class="hs-identifier hs-type">EvVarDest</span></a></span><span> </span><span id="local-6989586621681174877"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174877"><span class="hs-identifier hs-var">ev_id</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174877"><span class="hs-identifier hs-var">ev_id</span></a></span><span>
</span><span id="line-435"></span><span>          </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#HoleDest"><span class="hs-identifier hs-type">HoleDest</span></a></span><span> </span><span id="local-6989586621681174875"><span class="annot"><span class="annottext">CoercionHole
</span><a href="#local-6989586621681174875"><span class="hs-identifier hs-var">hole</span></a></span></span><span>   </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-comment">-- See Note [Quantifying over coercion holes]</span><span>
</span><span id="line-436"></span><span>                             </span><span class="hs-keyword">do</span><span> </span><span class="hs-special">{</span><span> </span><span id="local-6989586621681174874"><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174874"><span class="hs-identifier hs-var">ev_id</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall gbl lcl. TcType -&gt; TcRnIf gbl lcl TcTyVar
</span><a href="GHC.Tc.Utils.TcMType.html#newEvVar"><span class="hs-identifier hs-var">newEvVar</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174880"><span class="hs-identifier hs-var">pred</span></a></span><span>
</span><span id="line-437"></span><span>                                </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">CoercionHole -&gt; Coercion -&gt; TcRn ()
</span><a href="GHC.Tc.Utils.TcMType.html#fillCoercionHole"><span class="hs-identifier hs-var">fillCoercionHole</span></a></span><span> </span><span class="annot"><span class="annottext">CoercionHole
</span><a href="#local-6989586621681174875"><span class="hs-identifier hs-var">hole</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyVar -&gt; Coercion
</span><a href="GHC.Tc.Types.Evidence.html#mkTcCoVarCo"><span class="hs-identifier hs-var">mkTcCoVarCo</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174874"><span class="hs-identifier hs-var">ev_id</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-438"></span><span>                                </span><span class="hs-special">;</span><span> </span><span class="annot"><span class="annottext">TcTyVar -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall (m :: * -&gt; *) a. Monad m =&gt; a -&gt; m a
</span><a href="../../base/src/GHC.Base.html#return"><span class="hs-identifier hs-var">return</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyVar
</span><a href="#local-6989586621681174874"><span class="hs-identifier hs-var">ev_id</span></a></span><span> </span><span class="hs-special">}</span><span>
</span><span id="line-439"></span><span>    </span><span class="annot"><a href="#local-6989586621681174887"><span class="hs-identifier hs-var">mk_quant_ev</span></a></span><span> </span><span id="local-6989586621681174871"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174871"><span class="hs-identifier hs-var">ct</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">String -&gt; MsgDoc -&gt; IOEnv (Env TcGblEnv TcLclEnv) TcTyVar
forall a. HasCallStack =&gt; String -&gt; MsgDoc -&gt; a
</span><a href="GHC.Utils.Outputable.html#pprPanic"><span class="hs-identifier hs-var">pprPanic</span></a></span><span> </span><span class="annot"><span class="annottext">String
</span><span class="hs-string">&quot;mk_quant_ev&quot;</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; MsgDoc
forall a. Outputable a =&gt; a -&gt; MsgDoc
</span><a href="GHC.Utils.Outputable.html#ppr"><span class="hs-identifier hs-var">ppr</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174871"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-440"></span><span>
</span><span id="line-441"></span><span>
</span><span id="line-442"></span><span class="annot"><a href="GHC.Tc.Gen.Rule.html#getRuleQuantCts"><span class="hs-identifier hs-type">getRuleQuantCts</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-443"></span><span class="hs-comment">-- Extract all the constraints we can quantify over,</span><span>
</span><span id="line-444"></span><span class="hs-comment">--   also returning the depleted WantedConstraints</span><span>
</span><span id="line-445"></span><span class="hs-comment">--</span><span>
</span><span id="line-446"></span><span class="hs-comment">-- NB: we must look inside implications, because with</span><span>
</span><span id="line-447"></span><span class="hs-comment">--     -fdefer-type-errors we generate implications rather eagerly;</span><span>
</span><span id="line-448"></span><span class="hs-comment">--     see GHC.Tc.Utils.Unify.implicationNeeded. Not doing so caused #14732.</span><span>
</span><span id="line-449"></span><span class="hs-comment">--</span><span>
</span><span id="line-450"></span><span class="hs-comment">-- Unlike simplifyInfer, we don't leave the WantedConstraints unchanged,</span><span>
</span><span id="line-451"></span><span class="hs-comment">--   and attempt to solve them from the quantified constraints.  That</span><span>
</span><span id="line-452"></span><span class="hs-comment">--   nearly works, but fails for a constraint like (d :: Eq Int).</span><span>
</span><span id="line-453"></span><span class="hs-comment">--   We /do/ want to quantify over it, but the short-cut solver</span><span>
</span><span id="line-454"></span><span class="hs-comment">--   (see GHC.Tc.Solver.Interact Note [Shortcut solving]) ignores the quantified</span><span>
</span><span id="line-455"></span><span class="hs-comment">--   and instead solves from the top level.</span><span>
</span><span id="line-456"></span><span class="hs-comment">--</span><span>
</span><span id="line-457"></span><span class="hs-comment">--   So we must partition the WantedConstraints ourselves</span><span>
</span><span id="line-458"></span><span class="hs-comment">--   Not hard, but tiresome.</span><span>
</span><span id="line-459"></span><span>
</span><span id="line-460"></span><span id="getRuleQuantCts"><span class="annot"><span class="annottext">getRuleQuantCts :: WantedConstraints -&gt; (Cts, WantedConstraints)
</span><a href="GHC.Tc.Gen.Rule.html#getRuleQuantCts"><span class="hs-identifier hs-var hs-var">getRuleQuantCts</span></a></span></span><span> </span><span id="local-6989586621681174869"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174869"><span class="hs-identifier hs-var">wc</span></a></span></span><span>
</span><span id="line-461"></span><span>  </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; WantedConstraints -&gt; (Cts, WantedConstraints)
</span><a href="#local-6989586621681174868"><span class="hs-identifier hs-var">float_wc</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="GHC.Types.Var.Set.html#emptyVarSet"><span class="hs-identifier hs-var">emptyVarSet</span></a></span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174869"><span class="hs-identifier hs-var">wc</span></a></span><span>
</span><span id="line-462"></span><span>  </span><span class="hs-keyword">where</span><span>
</span><span id="line-463"></span><span>    </span><span class="annot"><a href="#local-6989586621681174868"><span class="hs-identifier hs-type">float_wc</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcTyCoVarSet"><span class="hs-identifier hs-type">TcTyCoVarSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WantedConstraints"><span class="hs-identifier hs-type">WantedConstraints</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-464"></span><span>    </span><span id="local-6989586621681174868"><span class="annot"><span class="annottext">float_wc :: TcTyCoVarSet -&gt; WantedConstraints -&gt; (Cts, WantedConstraints)
</span><a href="#local-6989586621681174868"><span class="hs-identifier hs-var hs-var">float_wc</span></a></span></span><span> </span><span id="local-6989586621681174866"><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174866"><span class="hs-identifier hs-var">skol_tvs</span></a></span></span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#WC"><span class="hs-identifier hs-type">WC</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">wc_simple :: WantedConstraints -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#wc_simple"><span class="hs-identifier hs-var">wc_simple</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681174863"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174863"><span class="hs-identifier hs-var">simples</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">wc_impl :: WantedConstraints -&gt; Bag Implication
</span><a href="GHC.Tc.Types.Constraint.html#wc_impl"><span class="hs-identifier hs-var">wc_impl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681174861"><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174861"><span class="hs-identifier hs-var">implics</span></a></span></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">wc_holes :: WantedConstraints -&gt; Bag Hole
</span><a href="GHC.Tc.Types.Constraint.html#wc_holes"><span class="hs-identifier hs-var">wc_holes</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span id="local-6989586621681174859"><span class="annot"><span class="annottext">Bag Hole
</span><a href="#local-6989586621681174859"><span class="hs-identifier hs-var">holes</span></a></span></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-465"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174858"><span class="hs-identifier hs-var">simple_yes</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#andCts"><span class="hs-operator hs-var">`andCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174856"><span class="hs-identifier hs-var">implic_yes</span></a></span><span>
</span><span id="line-466"></span><span>        </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="GHC.Tc.Types.Constraint.html#emptyWC"><span class="hs-identifier hs-var">emptyWC</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">wc_simple :: Cts
</span><a href="GHC.Tc.Types.Constraint.html#wc_simple"><span class="hs-identifier hs-var">wc_simple</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174854"><span class="hs-identifier hs-var">simple_no</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">wc_impl :: Bag Implication
</span><a href="GHC.Tc.Types.Constraint.html#wc_impl"><span class="hs-identifier hs-var">wc_impl</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174853"><span class="hs-identifier hs-var">implics_no</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">wc_holes :: Bag Hole
</span><a href="GHC.Tc.Types.Constraint.html#wc_holes"><span class="hs-identifier hs-var">wc_holes</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bag Hole
</span><a href="#local-6989586621681174859"><span class="hs-identifier hs-var">holes</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-467"></span><span>     </span><span class="hs-keyword">where</span><span>
</span><span id="line-468"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621681174858"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174858"><span class="hs-identifier hs-var">simple_yes</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174854"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174854"><span class="hs-identifier hs-var">simple_no</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Ct -&gt; Bool) -&gt; Cts -&gt; (Cts, Cts)
forall a. (a -&gt; Bool) -&gt; Bag a -&gt; (Bag a, Bag a)
</span><a href="GHC.Data.Bag.html#partitionBag"><span class="hs-identifier hs-var">partitionBag</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; Ct -&gt; Bool
</span><a href="#local-6989586621681174851"><span class="hs-identifier hs-var">rule_quant_ct</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174866"><span class="hs-identifier hs-var">skol_tvs</span></a></span><span class="hs-special">)</span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174863"><span class="hs-identifier hs-var">simples</span></a></span><span>
</span><span id="line-469"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621681174856"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174856"><span class="hs-identifier hs-var">implic_yes</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174853"><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174853"><span class="hs-identifier hs-var">implics_no</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">(Cts -&gt; Implication -&gt; (Cts, Implication))
-&gt; Cts -&gt; Bag Implication -&gt; (Cts, Bag Implication)
forall acc x y.
(acc -&gt; x -&gt; (acc, y)) -&gt; acc -&gt; Bag x -&gt; (acc, Bag y)
</span><a href="GHC.Data.Bag.html#mapAccumBagL"><span class="hs-identifier hs-var">mapAccumBagL</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; Cts -&gt; Implication -&gt; (Cts, Implication)
</span><a href="#local-6989586621681174849"><span class="hs-identifier hs-var">float_implic</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174866"><span class="hs-identifier hs-var">skol_tvs</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-470"></span><span>                                                </span><span class="annot"><span class="annottext">Cts
forall a. Bag a
</span><a href="GHC.Data.Bag.html#emptyBag"><span class="hs-identifier hs-var">emptyBag</span></a></span><span> </span><span class="annot"><span class="annottext">Bag Implication
</span><a href="#local-6989586621681174861"><span class="hs-identifier hs-var">implics</span></a></span><span>
</span><span id="line-471"></span><span>
</span><span id="line-472"></span><span>    </span><span class="annot"><a href="#local-6989586621681174849"><span class="hs-identifier hs-type">float_implic</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcTyCoVarSet"><span class="hs-identifier hs-type">TcTyCoVarSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Implication"><span class="hs-identifier hs-type">Implication</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="hs-special">(</span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Cts"><span class="hs-identifier hs-type">Cts</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Implication"><span class="hs-identifier hs-type">Implication</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-473"></span><span>    </span><span id="local-6989586621681174849"><span class="annot"><span class="annottext">float_implic :: TcTyCoVarSet -&gt; Cts -&gt; Implication -&gt; (Cts, Implication)
</span><a href="#local-6989586621681174849"><span class="hs-identifier hs-var hs-var">float_implic</span></a></span></span><span> </span><span id="local-6989586621681174847"><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174847"><span class="hs-identifier hs-var">skol_tvs</span></a></span></span><span> </span><span id="local-6989586621681174846"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174846"><span class="hs-identifier hs-var">yes1</span></a></span></span><span> </span><span id="local-6989586621681174845"><span class="annot"><span class="annottext">Implication
</span><a href="#local-6989586621681174845"><span class="hs-identifier hs-var">imp</span></a></span></span><span>
</span><span id="line-474"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174846"><span class="hs-identifier hs-var">yes1</span></a></span><span> </span><span class="annot"><span class="annottext">Cts -&gt; Cts -&gt; Cts
</span><a href="GHC.Tc.Types.Constraint.html#andCts"><span class="hs-operator hs-var">`andCts`</span></a></span><span> </span><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174844"><span class="hs-identifier hs-var">yes2</span></a></span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Implication
</span><a href="#local-6989586621681174845"><span class="hs-identifier hs-var">imp</span></a></span><span> </span><span class="hs-special">{</span><span> </span><span class="annot"><span class="annottext">ic_wanted :: WantedConstraints
</span><a href="GHC.Tc.Types.Constraint.html#ic_wanted"><span class="hs-identifier hs-var">ic_wanted</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174842"><span class="hs-identifier hs-var">no</span></a></span><span> </span><span class="hs-special">}</span><span class="hs-special">)</span><span>
</span><span id="line-475"></span><span>      </span><span class="hs-keyword">where</span><span>
</span><span id="line-476"></span><span>        </span><span class="hs-special">(</span><span id="local-6989586621681174844"><span class="annot"><span class="annottext">Cts
</span><a href="#local-6989586621681174844"><span class="hs-identifier hs-var">yes2</span></a></span></span><span class="hs-special">,</span><span> </span><span id="local-6989586621681174842"><span class="annot"><span class="annottext">WantedConstraints
</span><a href="#local-6989586621681174842"><span class="hs-identifier hs-var">no</span></a></span></span><span class="hs-special">)</span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; WantedConstraints -&gt; (Cts, WantedConstraints)
</span><a href="#local-6989586621681174868"><span class="hs-identifier hs-var">float_wc</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174841"><span class="hs-identifier hs-var">new_skol_tvs</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Implication -&gt; WantedConstraints
</span><a href="GHC.Tc.Types.Constraint.html#ic_wanted"><span class="hs-identifier hs-var hs-var">ic_wanted</span></a></span><span> </span><span class="annot"><span class="annottext">Implication
</span><a href="#local-6989586621681174845"><span class="hs-identifier hs-var">imp</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-477"></span><span>        </span><span id="local-6989586621681174841"><span class="annot"><span class="annottext">new_skol_tvs :: TcTyCoVarSet
</span><a href="#local-6989586621681174841"><span class="hs-identifier hs-var hs-var">new_skol_tvs</span></a></span></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174847"><span class="hs-identifier hs-var">skol_tvs</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; [TcTyVar] -&gt; TcTyCoVarSet
</span><a href="GHC.Types.Var.Set.html#extendVarSetList"><span class="hs-operator hs-var">`extendVarSetList`</span></a></span><span> </span><span class="annot"><span class="annottext">Implication -&gt; [TcTyVar]
</span><a href="GHC.Tc.Types.Constraint.html#ic_skols"><span class="hs-identifier hs-var hs-var">ic_skols</span></a></span><span> </span><span class="annot"><span class="annottext">Implication
</span><a href="#local-6989586621681174845"><span class="hs-identifier hs-var">imp</span></a></span><span>
</span><span id="line-478"></span><span>
</span><span id="line-479"></span><span>    </span><span class="annot"><a href="#local-6989586621681174851"><span class="hs-identifier hs-type">rule_quant_ct</span></a></span><span> </span><span class="hs-glyph">::</span><span> </span><span class="annot"><a href="GHC.Tc.Utils.TcType.html#TcTyCoVarSet"><span class="hs-identifier hs-type">TcTyCoVarSet</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><a href="GHC.Tc.Types.Constraint.html#Ct"><span class="hs-identifier hs-type">Ct</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="hs-identifier hs-type">Bool</span></span><span>
</span><span id="line-480"></span><span>    </span><span id="local-6989586621681174851"><span class="annot"><span class="annottext">rule_quant_ct :: TcTyCoVarSet -&gt; Ct -&gt; Bool
</span><a href="#local-6989586621681174851"><span class="hs-identifier hs-var hs-var">rule_quant_ct</span></a></span></span><span> </span><span id="local-6989586621681174838"><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174838"><span class="hs-identifier hs-var">skol_tvs</span></a></span></span><span> </span><span id="local-6989586621681174837"><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174837"><span class="hs-identifier hs-var">ct</span></a></span></span><span>
</span><span id="line-481"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><a href="GHC.Core.Predicate.html#EqPred"><span class="hs-identifier hs-type">EqPred</span></a></span><span> </span><span class="annot"><span class="annottext">EqRel
</span><span class="hs-identifier">_</span></span><span> </span><span id="local-6989586621681174835"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174835"><span class="hs-identifier hs-var">t1</span></a></span></span><span> </span><span id="local-6989586621681174834"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174834"><span class="hs-identifier hs-var">t2</span></a></span></span><span> </span><span class="hs-glyph">&lt;-</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Pred
</span><a href="GHC.Core.Predicate.html#classifyPredType"><span class="hs-identifier hs-var">classifyPredType</span></a></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">Ct -&gt; TcType
</span><a href="GHC.Tc.Types.Constraint.html#ctPred"><span class="hs-identifier hs-var">ctPred</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174837"><span class="hs-identifier hs-var">ct</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-482"></span><span>      </span><span class="hs-special">,</span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool
</span><span class="hs-identifier hs-var">not</span></span><span> </span><span class="hs-special">(</span><span class="annot"><span class="annottext">TcType -&gt; TcType -&gt; Bool
</span><a href="#local-6989586621681174830"><span class="hs-identifier hs-var">ok_eq</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174835"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174834"><span class="hs-identifier hs-var">t2</span></a></span><span class="hs-special">)</span><span>
</span><span id="line-483"></span><span>       </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>        </span><span class="hs-comment">-- Note [RULE quantification over equalities]</span><span>
</span><span id="line-484"></span><span>      </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>
</span><span id="line-485"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Ct -&gt; TcTyCoVarSet
</span><a href="GHC.Tc.Types.Constraint.html#tyCoVarsOfCt"><span class="hs-identifier hs-var">tyCoVarsOfCt</span></a></span><span> </span><span class="annot"><span class="annottext">Ct
</span><a href="#local-6989586621681174837"><span class="hs-identifier hs-var">ct</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet -&gt; TcTyCoVarSet -&gt; Bool
</span><a href="GHC.Types.Var.Set.html#disjointVarSet"><span class="hs-operator hs-var">`disjointVarSet`</span></a></span><span> </span><span class="annot"><span class="annottext">TcTyCoVarSet
</span><a href="#local-6989586621681174838"><span class="hs-identifier hs-var">skol_tvs</span></a></span><span>
</span><span id="line-486"></span><span>
</span><span id="line-487"></span><span>    </span><span id="local-6989586621681174830"><span class="annot"><span class="annottext">ok_eq :: TcType -&gt; TcType -&gt; Bool
</span><a href="#local-6989586621681174830"><span class="hs-identifier hs-var hs-var">ok_eq</span></a></span></span><span> </span><span id="local-6989586621681174826"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174826"><span class="hs-identifier hs-var">t1</span></a></span></span><span> </span><span id="local-6989586621681174825"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174825"><span class="hs-identifier hs-var">t2</span></a></span></span><span>
</span><span id="line-488"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174826"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">HasDebugCallStack =&gt; TcType -&gt; TcType -&gt; Bool
TcType -&gt; TcType -&gt; Bool
</span><a href="GHC.Tc.Utils.TcType.html#tcEqType"><span class="hs-operator hs-var">`tcEqType`</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174825"><span class="hs-identifier hs-var">t2</span></a></span><span> </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-489"></span><span>       </span><span class="hs-glyph">|</span><span> </span><span class="annot"><span class="annottext">Bool
</span><a href="../../base/src/GHC.Base.html#otherwise"><span class="hs-identifier hs-var">otherwise</span></a></span><span>        </span><span class="hs-glyph">=</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Bool
</span><a href="#local-6989586621681174823"><span class="hs-identifier hs-var">is_fun_app</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174826"><span class="hs-identifier hs-var">t1</span></a></span><span> </span><span class="annot"><span class="annottext">Bool -&gt; Bool -&gt; Bool
</span><span class="hs-operator hs-var">||</span></span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Bool
</span><a href="#local-6989586621681174823"><span class="hs-identifier hs-var">is_fun_app</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174825"><span class="hs-identifier hs-var">t2</span></a></span><span>
</span><span id="line-490"></span><span>
</span><span id="line-491"></span><span>    </span><span id="local-6989586621681174823"><span class="annot"><span class="annottext">is_fun_app :: TcType -&gt; Bool
</span><a href="#local-6989586621681174823"><span class="hs-identifier hs-var hs-var">is_fun_app</span></a></span></span><span> </span><span id="local-6989586621681174821"><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174821"><span class="hs-identifier hs-var">ty</span></a></span></span><span>   </span><span class="hs-comment">-- ty is of form (F tys) where F is a type function</span><span>
</span><span id="line-492"></span><span>      </span><span class="hs-glyph">=</span><span> </span><span class="hs-keyword">case</span><span> </span><span class="annot"><span class="annottext">TcType -&gt; Maybe TyCon
</span><a href="GHC.Core.Type.html#tyConAppTyCon_maybe"><span class="hs-identifier hs-var">tyConAppTyCon_maybe</span></a></span><span> </span><span class="annot"><span class="annottext">TcType
</span><a href="#local-6989586621681174821"><span class="hs-identifier hs-var">ty</span></a></span><span> </span><span class="hs-keyword">of</span><span>
</span><span id="line-493"></span><span>          </span><span class="annot"><a href="../../base/src/GHC.Maybe.html#Just"><span class="hs-identifier hs-type">Just</span></a></span><span> </span><span id="local-6989586621681174819"><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681174819"><span class="hs-identifier hs-var">tc</span></a></span></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">TyCon -&gt; Bool
</span><a href="GHC.Core.TyCon.html#isTypeFamilyTyCon"><span class="hs-identifier hs-var">isTypeFamilyTyCon</span></a></span><span> </span><span class="annot"><span class="annottext">TyCon
</span><a href="#local-6989586621681174819"><span class="hs-identifier hs-var">tc</span></a></span><span>
</span><span id="line-494"></span><span>          </span><span class="annot"><span class="annottext">Maybe TyCon
</span><a href="../../base/src/GHC.Maybe.html#Nothing"><span class="hs-identifier hs-var">Nothing</span></a></span><span> </span><span class="hs-glyph">-&gt;</span><span> </span><span class="annot"><span class="annottext">Bool
</span><span class="hs-identifier hs-var">False</span></span><span>
</span><span id="line-495"></span></pre></body></html>